package org.abstractmeta.commandify.core.command.map;

import org.abstractmeta.commandify.Commandify;
import org.abstractmeta.commandify.command.Command;
import org.abstractmeta.commandify.core.CommandsImpl;
import org.abstractmeta.reflectify.Accessor;

import java.util.Collection;
import java.util.Map;

/**
 * Represents map commands, it override ancestor with map value implementation.
 *
 * @author Adrian Witas
 */
public class MapCommands<T> extends CommandsImpl<T> {

    @SuppressWarnings("unchecked")
    public MapCommands(Class ownerType) {
        super(ownerType);
    }

    public MapCommands(Class<T> ownerType, Collection<Command<T>> commands) {
        super(ownerType, commands);
    }


    @Override
    @SuppressWarnings("unchecked")
    public Accessor<T, Object> getAccessor(final Object source) {
        Accessor accessor = new Accessor<Map, Object>() {

            @Override
            public Object get(Map instance) {
                return instance.get(source);
            }
        };
        return accessor;
    }
}
